package com.zivwu.library;


import com.orhanobut.logger.Logger;
import com.zivwu.library.rx.RxBus;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;


public class Presenter {

    private final RxBus rxBus;

    public Presenter() {
        rxBus = RxBus.getInstance();
        initEvent();
    }

    public void initEvent() {
        Observable.create(new ObservableOnSubscribe<Object>() {
            @Override
            public void subscribe(@NonNull ObservableEmitter<Object> e) throws Exception {

            }
        });


        rxBus.toObservable().subscribe(new Consumer<Object>() {
            @Override
            public void accept(Object o) throws Exception {
                log("rx1");
            }
        });

        rxBus.toObservable().subscribe(new Consumer<Object>() {
            @Override
            public void accept(Object s) throws Exception {
                log("onGetInfo+2");
                if (s instanceof String)
                    log((String) s);
            }
        });

        rxBus.toObservable(String.class).subscribe(new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                log((String) s);
            }
        });
    }


    private void log(String msg) {
        Logger.d(msg);
    }
}
